home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programmer's Power Pack
/
Delphi Volume 1.iso
/
e_to_l
/
edsspell
/
absbuff.pas
next >
Wrap
Pascal/Delphi Source File
|
1996-09-15
|
12KB
|
351 lines
(* ABSBUFF.PAS - Copyright (c) 1995-1996, Eminent Domain Software *)
unit AbsBuff;
{-Abstract buffer manager for EDSSpell component}
{-also includes native Delphi CustomEdit buffer manager}
interface
uses
Classes, Controls, Graphics, SysUtils, Forms, StdCtrls,
WinProcs, WinTypes,
MemoUtil, SpellGbl, Words;
type
TAbsBuffer = class (TObject) {abstract buffer manager}
private
{ Private declarations }
FSize: Longint; {size of buffer}
FCurPosPtr: PChar; {points to current character in buffer}
FBeginPos: Longint; {beginning position of word in buffer}
FEndPos: Longint; {ending position of word in buffer}
FParent: TControl; {parent control, if any}
FAllNums: Boolean; {TRUE if the current word is all numbers}
protected
{ Protected declarations }
public
{ Public declarations }
Buffer: PBigBuffer; {pointer to the buffer}
CurPos: Longint; {current location in the buffer}
constructor Create (AParent: TControl); dynamic;
destructor Destroy; override;
procedure InitParms;
{-initializes buffer parameters}
function IsModified: Boolean; virtual; abstract;
{-returns TRUE if parent had been modified}
procedure SetModified (NowModified: Boolean); virtual; abstract;
{-sets parents modified flag}
function GetYPos: integer; virtual;
{-gets the current y location of the highlighted word (absolute screen)}
function GetNextWord: string; dynamic; abstract;
{-returns the next word in the buffer}
procedure MoveBackOneWord; dynamic; abstract;
{-moves back to the beginning of the current word}
procedure UpdateBuffer; dynamic; abstract;
{-updates the buffer from the parent component, if any}
procedure SetSelectedText; dynamic;
{-highlights the current word using FBeginPos & FEndPos}
procedure ReplaceWord (WithWord: string); dynamic; abstract;
{-replaces the current word with the word provided}
procedure WordCount (var NumWords, UniqueWords: Longint); dynamic;
{-returns the number of words in buffer}
{ Property declarations }
property BufSize: Longint read FSize
write FSize;
property PCurPos: PChar read FCurPosPtr
write FCurPosPtr;
property BeginPos: Longint read FBeginPos
write FBeginPos;
property EndPos: Longint read FEndPos
write FEndPos;
property Parent: TControl read FParent
write FParent;
property Modified: Boolean read IsModified
write SetModified;
property YPos: Integer read GetYPos;
property AllNumbers: Boolean read FAllNums
write FAllNums;
end; { TAbsBuffer }
TPCharBuffer = class (TAbsBuffer) {PChar buffer manager}
private
{ Private declarations }
FModified: Boolean; {Internal modified flag}
FPChar: PChar; {Parent Buffer}
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create (AParent: TControl); override;
constructor CreateSpecial (ParentBuffer: PChar); dynamic;
function IsModified: Boolean; override;
{-returns TRUE if parent had been modified}
procedure SetModified (NowModified: Boolean); override;
{-sets parents modified flag}
function GetNextWord: string; override;
{-returns the next word in the buffer}
procedure MoveBackOneWord; override;
{-moves back to the beginning of the current word}
procedure UpdateBuffer; override;
{-updates the buffer from the parent component, if any}
procedure ReplaceWord (WithWord: string); override;
{-replaces the current word with the word provided}
end; { TPCharBuffer }
TCEBuffer = class (TPCharBuffer) {TCustomEdit buffer manager}
private {works for TMemo & TEdit}
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create (AParent: TControl); override;
function IsModified: Boolean; override;
{-returns TRUE if parent had been modified}
procedure SetModified (NowModified: Boolean); override;
{-sets parents modified flag}
function GetYPos: integer; override;
{-gets the current y location of the highlighted word (absolute screen)}
procedure SetSelectedText; override;
{-highlights the current word using BeginPos & EndPos}
procedure UpdateBuffer; override;
{-updates the buffer from the parent component, if any}
procedure ReplaceWord (WithWord: string); override;
{-replaces the current word with the word provided}
end; { TCEBuffer }
implementation
{Abstract Buffer Manager}
constructor TAbsBuffer.Create (AParent: TControl);
begin
inherited Create;
FParent := AParent;
GetMem (Buffer, MaxBuffer);
InitParms;
UpdateBuffer;
end; { TAbsBuffer.Create }
procedure TAbsBuffer.InitParms;
{-initializes buffer parameters}
begin
CurPos := 1;
PCurPos := @Buffer^[1];
end; { TAbsBuffer.InitParms }
function TAbsBuffer.GetYPos: integer;
{-gets the current y location of the highlighted word (absolute screen)}
begin
Result := 0;
end; { TAbsBuffer.GetYPos }
procedure TAbsBuffer.WordCount (var NumWords, UniqueWords: Longint);
{-returns the number of words in buffer}
var
UniqueList: TStringList;
WordSt: String;
Words: String;
UniqueSt: String;
begin
InitParms;
NumWords := 0;
UniqueWords := 0;
UniqueList := TStringList.Create;
if WordForm = nil then
WordForm := TWordForm.Create (Application);
if not WordForm.Visible then WordForm.Show;
repeat
WordSt := UpperCase (GetNextWord);
if WordSt <> '' then
begin
Inc (NumWords);
if UniqueList.IndexOf (WordSt) = (-1) then
UniqueList.Add (WordSt);
end; { if... }
Str (NumWords, Words);
Str (UniqueList.Count, UniqueSt);
WordForm.lblWords.Caption := Words;
WordForm.lblUniqueWords.Caption := UniqueSt;
Application.ProcessMessages;
if not WordForm.Visible then {form was closed}
begin
NumWords := 0;
UniqueList.Clear;
Break;
end; { if... }
until WordSt = '';
UniqueWords := UniqueList.Count;
UniqueList.Free;
end; { TAbsBuffer.WordCount }
procedure TAbsBuffer.SetSelectedText;
begin
{do nothing}
end; { TabsBuffer.SetSelectedText }
destructor TAbsBuffer.Destroy;
begin
if Buffer <> nil then
FreeMem (Buffer, MaxBuffer);
inherited Destroy;
end; { TAbsBuffer.Destroy }
{PChar Buffer Manager}
constructor TPCharBuffer.Create (AParent: TControl);
begin
inherited Create (AParent);
FModified := FALSE;
end; { TPCharBuffer.Create }
constructor TPCharBuffer.CreateSpecial (ParentBuffer: PChar);
begin
inherited Create (nil);
FPChar := ParentBuffer;
FModified := FALSE;
end; { TPCharBuffer.CreateSpecial }
function TPCharBuffer.IsModified: Boolean;
{-returns TRUE if parent had been modified}
begin
Result := FModified;
end; { TPCharBuffer.IsModified }
procedure TPCharBuffer.SetModified (NowModified: Boolean);
{-sets parents modified flag}
begin
FModified := NowModified;
end; { TPCharBuffer.SetModified }
function TPCharBuffer.GetNextWord: string;
{-returns the next word in the buffer}
var
S: string; {string being constructed}
begin
BeginPos := CurPos;
EndPos := CurPos;
S := ''